package com.longqinuo.mycarservice.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;

import com.longqinuo.mycarservice.R;
import com.longqinuo.mycarservice.entity.News;

import java.util.List;

/**
 * 自定义快递电话列表适配器
 * Created by zxw on 2016/6/8.
 */
public class NewsAdapter extends BaseAdapter {
    private Context context;
    private List<News> mList;
    private ImageLoader mImageLoader;
    public NewsAdapter(Context context, List<News> list, ImageLoader imageLoader) {
        // TODO Auto-generated constructor stub
        this.context = context;
        this.mList = list;
        this.mImageLoader = imageLoader;
    }
    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return mList.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return mList.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.news_item_layout, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        News n = mList.get(position);
        holder.image.setImageUrl(n.getImage(),mImageLoader);
        holder.title.setText(n.getTitle());


        holder.time.setText(n.getTime());
        holder.lookCount.setText(n.getLookCount());

        return convertView;
    }

    public class ViewHolder{

        public ViewHolder(View itemView) {
            this.image = (NetworkImageView) itemView.findViewById(R.id.iv_image_news);
            this.title = (TextView) itemView.findViewById(R.id.tv_title_news);
            this.time = (TextView) itemView.findViewById(R.id.tv_time_news);
            this.lookCount = (TextView) itemView.findViewById(R.id.tv_look_count_news);
        }

        private NetworkImageView image;
        private TextView title;
        private TextView time;
        private TextView lookCount;
    }
}
